package chloroform.json.comp

import chloroform.json.JsonBuilderFactory
import argo.jdom.{JsonRootNode, JsonNode}

/**
 * User: zslajchrt
 * Date: 16.5.11
 * Time: 15:54
 */
class ServerMessages

class AbstractMessage(messageType: String) extends JsonComposite {
  val msgType = string(messageType)
}

class EditContext(contextName: String, pageId: String, canBack: Boolean) extends JsonComposite {
  val name = string(contextName)
  val page = string(pageId)
  val canMoveBack = boolean(canBack)
}


class AbstractServerMessage(messageType: String) extends AbstractMessage(messageType)

class AbstractContextualServerMessage(messageType: String, ctx: JsonBuilderFactory[JsonRootNode])
  extends AbstractServerMessage(messageType) {

  val context = struct(ctx)

}

class EditCookie(ctx: JsonBuilderFactory[JsonRootNode], fieldBuilderFactories: List[JsonBuilderFactory[JsonRootNode]])
  extends AbstractContextualServerMessage("EditCookie", ctx) {

  val fields = array(struct())
  fields <= fieldBuilderFactories

}

class Hints(ctx: JsonBuilderFactory[JsonRootNode], itemBuilderFactories: List[JsonBuilderFactory[JsonRootNode]])
  extends AbstractContextualServerMessage("Hints", ctx) {
  val items = array(struct())
  items <= itemBuilderFactories
}


class ResultStarterReady(ctx: JsonBuilderFactory[JsonRootNode])
  extends AbstractContextualServerMessage("ResultStarterReady", ctx)


class Result(ctx: JsonBuilderFactory[JsonRootNode], cont: String) extends AbstractContextualServerMessage("Result", ctx) {
  val content = string(cont)
}

class End extends AbstractContextualServerMessage("End", new EditContext("", "", false))


//class ProjectEntries(entryBuilderFactories: Map[String, JsonBuilderFactory[JsonNode]]) extends AbstractServerMessage("ProjectEntries") {
class ProjectEntries(entryBuilderFactories: List[JsonBuilderFactory[JsonRootNode]]) extends AbstractServerMessage("ProjectEntries") {
  val entries = array(struct())
  entries <= entryBuilderFactories
  //val entries = new MapJsonComposite(entryBuilderFactories)
}